package com.kaishengit.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.kaishengit.pojo.Issues;
import com.kaishengit.pojo.Project;

public class DataUtil {
	
	public static List<Map<String,Integer>> getProjectData(List<Project> projects){
		List<Map<String,Integer>> list = new ArrayList<Map<String,Integer>>();
		for(Project project : projects){
			Map<String,Integer> mapson = new HashMap<String, Integer>();
			int[] data = getData(project);
			mapson.put("task", data[0]);
			mapson.put("bug", data[1]);
			mapson.put("idea", data[2]);
			mapson.put("id", project.getId());
			list.add(mapson);
		}
		return list;
	}
	
	public static int[] getData(Project project){
		int[] result = new int[3];
		List<Issues> issuesList = project.getIssues();
		int taskNum = 0;
		int bugNum = 0;
		int ideaNum = 0;
		for(Issues issues : issuesList){
			int type = issues.getType();
			if(type == 1){
				taskNum ++;
			} else if(type == 2){
				bugNum ++;
			} else if(type == 3){
				ideaNum ++;
			}
		}
		result[0] = taskNum;
		result[1] = bugNum;
		result[2] = ideaNum;
		return result;
	}
}
